package com.cloud.drore.eboss.supplier.controller;

import com.cloud.drore.eboos.common.base.ResultMessage;
import com.cloud.drore.eboos.common.entity.supplier.ProductRelation;
import com.cloud.drore.eboos.exception.BusinessException;
import com.cloud.drore.eboss.login.user.Anon;
import com.cloud.drore.eboss.supplier.entity.po.ProductRelationPo;
import com.cloud.drore.eboss.supplier.service.impl.ProductRelationServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.sql.ResultSet;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/9 11:06 <br>
 * @Author: <a href="575842778@qq.com">郑永涛</a>
 */
@RestController
@RequestMapping("/productRelation")
@Api(value = "/提供分销商查询公共产品接口", description = "提供分销商查询公共产品接口-郑永涛",hidden = true)
public class ProductRelationController {

    @Resource
    ProductRelationServiceImpl productRelationService;

    public ResultSet get(ResultSet resultSet){
        return null;
    }


    @ApiOperation(value = "保存信息")
    @PostMapping(value = "/save")
    public ResultMessage<ProductRelation> save(@RequestBody @Validated({ProductRelation.SAVE.class}) ProductRelation productRelation){
        return new ResultMessage(productRelationService.insert(productRelation));
    }

    @ApiOperation(value = "更新信息")
    @PutMapping(value = "/update")
    public ResultMessage<ProductRelation> update(@RequestBody @Valid ProductRelation productRelation){
        return new ResultMessage(productRelationService.updateByPrimaryKey(productRelation));
    }

    @ApiOperation(value = "删除信息")
    @DeleteMapping(value = "/delete/{id}")
    public ResultMessage<ProductRelation> delete(@PathVariable("id") Long id){
        return new ResultMessage(productRelationService.deleteByPrimaryKey(id));
    }

    @Anon
    @ApiOperation(value = "通过id获取信息")
    @GetMapping(value = "/{id}")
    public ResultMessage<ProductRelation> get(@PathVariable("id") Long id){
        return new ResultMessage(productRelationService.findById(id));
    }

    @ApiOperation(value = "根据条件查询公共产品信息")
    @PostMapping(value = "findByParam")
    public ResultMessage findByParam(@RequestBody ProductRelationPo relation){
        return new ResultMessage(productRelationService.findByParam(relation));
    }

    @Anon
    @ApiOperation(value = "根据产品类型和产品id查询公共产品信息")
    @GetMapping(value = "selectByTypeAndId/{type}/{productId}")
    public ResultMessage selectByTypeAndId(@PathVariable("type") String type,@PathVariable("productId") Long productId){
        return new ResultMessage(productRelationService.selectIdByTypeAndId(type,productId));
    }

    @ApiOperation(value = "根据供应商id查询产品编号")
    @GetMapping(value = "selectProductIdBySupplierId/{id}")
    public ResultMessage selectProductIdBySupplierId(@PathVariable("id") Long id){
        return new ResultMessage(productRelationService.selectProductIdBySupplierId(id));
    }

    @Anon
    @ApiOperation(value = "根据产品编号查询公共产品对象")
    @GetMapping(value = "selectProductByProNum/{proNum}")
    public ResultMessage selectProductByProNum(@PathVariable("proNum") String proNum)throws BusinessException {
        return new ResultMessage(productRelationService.selectProductByProNum(proNum));
    }

    @Anon
    @ApiOperation(value = "根据产品编号查询门票产品集合")
    @GetMapping(value = "selectProductListByProNum/{proNum}")
    public ResultMessage selectProductListByProNum(@PathVariable("proNum") String proNum)throws BusinessException {
        return new ResultMessage(productRelationService.selectProductListByProNum(proNum));
    }

    @Anon
    @ApiOperation(value = "根据产品编号查询消费点、景区、供应商")
    @GetMapping(value = "findPoiAndConsumeForDealer/{productNum}")
    public ResultMessage findPoiAndConsumeForDealer(@PathVariable("productNum") String productNum)throws BusinessException{
        return new ResultMessage(productRelationService.findPoiAndConsumeForDealer(productNum));
    }

}